<layout name="page" />
<block name="content">
	<input type="hidden" name="ajax" id="ajax" value="1">
	{:widget('page_header/simple',array('name'=>$flow_type['name']))}
	<div class="operate-panel">
		<a onclick="go_return_url()" class="btn">返回</a>
		<div class="split"></div>
		<a onclick="add()" class="btn" onclick="add();" >新增</a>
		<a id="btn_save" class="btn">保存</a>
		|
		<a onclick="del()"class="btn btn-del">删除</a>
	</div>
	<div class="sub-frame">
		<div class="sub-sidebar gray">
			<?php echo $menu ?>
		</div>
		<div class="sub-content gray">
			<form id="form_data" name="form_data" method="post" >
				<input type="hidden" name="id" id="id">
				<input type="hidden" id="flow_type_id" name="flow_type_id" value="{$flow_type.id}">
				<input type="hidden" id="confirm" name="confirm" >
				<input type="hidden" id="confirm_name" name="confirm_name" >
				<input type="hidden" id="consult" name="consult" >
				<input type="hidden" id="consult_name" name="consult_name">
				<input type="hidden" name="opmode" id="opmode" value="">
				<div class="layui-sub-form-item col-xs-12">
					<label class="input-label" for="name">名称*：</label>
					
						<input class="input" type="text" id="name" name="name" check="required" info="请输入名称">
					</div>
				</div>
				<div class="layui-sub-form-item col-xs-12">
					<label class="input-label" for="sort">条件：</label>
					
						<p class="input-static">
							<span id="condition_name"></span><a class="btn pull-right" onclick="popup_condition()">修改</a>
						</p>
					</div>
				</div>
				<div class="layui-sub-form-item col-xs-12">
					<label class="input-label" for="sort">审批：</label>
					
						<div id="confirm_wrap" class="input-box">
							<a class="add-on" onclick="popup_flow();"><i class="fa fa-user"></i> </a>
							<div class="wrap" >
								<span class="address_list">{$vo.confirm_name}</span>
								<span class="text" >
									<input class="letter" type="text"  >
								</span>
							</div>
							<div class="search dropdown ">
								<ul class="dropdown-menu"></ul>
							</div>
						</div>
					</div>
				</div>
				<div class="layui-sub-form-item col-xs-12">
					<label class="input-label" for="sort">协商：</label>
					
						<div id="consult_wrap" class="input-box">
							<a class="add-on" onclick="popup_flow();"> <i class="fa fa-user"></i> </a>
							<div class="wrap" >
								<span class="address_list">{$vo.consult_name}</span>
								<span class="text" >
									<input class="letter" type="text"  >
								</span>
							</div>
							<div class="search dropdown">
								<ul class="dropdown-menu"></ul>
							</div>
						</div>
					</div>
				</div>
				<div class="layui-sub-form-item">
					<label class="input-label" for="sort">排序：</label>
					<div class="input-block col-10">
						<input class="input" type="text" id="sort" name="sort" >
					</div>
				</div>

				<div class="layui-sub-form-item col-xs-12">
					<label class="input-label" for="is_del">状态：</label>
					<div class="input-block col-10">
						<select  class="input" name="is_del" id="is_del">
							<option  value="0">启用</option>
							<option value="1">禁用</option>
						</select>
					</div>
				</div>
				<div class="layui-sub-form-item">
					<label class="input-label" for="remark" >备注：</label>
					<div class="input-block" >
						<textarea class="textarea" name="remark" rows="5" class="col-xs-12" ></textarea>
					</div>
				</div>
			</form>
		</div>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		layui.use(['global'], function() {
			var $ = layui.jquery;

			$(document).on("dblclick", ".inputbox .address_list b", function() {
				$(this).parent().parent().remove();
			});

			$(document).ready(function() {
				$(".sub-sidebar .tree_menu  a").click(function() {
					$(".sub-sidebar .tree_menu  a").each(function() {
						$(this).attr("class", "");
					});
					$(this).attr("class", "active");
					send_ajax("{:url('FlowType/get_step')}", "id=" + $(this).attr("node"), function(data) {
						show_data(data);
					});
					return false;
				});
			});

			$("#btn_save").on('click', function() {
				if ($("#opmode").val() == "") {
					layer.msg("请选择要修改的数据");
					return false;
				}
				$("#confirm").val("");
				$("#confirm_wrap  span.address_list span").each(function() {
					$("#confirm").val($("#confirm").val() + $(this).attr("data") + '|');
				});

				$("#confirm_name").val("");
				$("#confirm_name").val($("#confirm_wrap span.address_list").html());

				$("#consult").val("");
				$("#consult_wrap span.address_list span").each(function() {
					$("#consult").val($("#consult").val() + $(this).attr("data") + '|');
				});

				send_form("form_data", "__SELF__", "__SELF__", function(ret) {
					if (ret.status) {
						layer.msg(ret.info);
						location.reload(true);
					} else {
						layer.msg(ret.info);
						return false;
					}
				});
			});

			$('#btn_del').on('click', function() {
				if ($(".sub-sidebar a.active").length == 0) {
					layer.msg('请选择要删除的数据');
					return false;
				}

				//信息框-例2
				layer.msg('确定要删除吗?', {
					time : 0,
					btn : ['确定', '取消'],
					yes : function(index) {
						var vars = $("#form_data").serialize();
						send_ajax("{:url('del_step')}", vars, function(ret) {
							if (ret.status) {
								layer.msg(ret.info, function() {
									location.reload(true);
								});
							}
						});
					},
					no : function(index) {
						layer.close(index);
					}
				});
			});
		});

		function popup_flow() {
			winopen("{:url('popup/flow')}", 560, 470);
		}

		function popup_condition() {
			$id = $("#id").val();
			if ($id == "") {
				layer.msg('请选择工作步骤');
				return false;
			} else {
				winopen(fix_url("{:url('FlowType/condition')}?step_id=" + $id), 560, 470);
			}
		}

		function add() {
			winopen("{:url('FlowType/add_step')}", 560, 470);
		};

		function show_data(result) {
			for (var s in result.data) {
				set_val(s, result.data[s]);
			}
			$("#confirm_wrap span.address_list").html(result.data['confirm_name']);
			$("#consult_wrap span.address_list").html(result.data['consult_name']);
			$('#condition_name').html(result.data['condition_name']);

			$("#opmode").val("edit");
		}

	</script>
</block>